package com.td.erhome.base;

import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import butterknife.ButterKnife;


/**
 * Activity基类
 */
public abstract class BaseActivity extends AppCompatActivity {

	@Override
	public final void onCreate(Bundle savedInstanceState) {
		setParams();
		super.onCreate(savedInstanceState);
		setContentView(getLayoutId());
		Log.d("BaseActivity", getClass().getSimpleName());
		isLand();
		ButterKnife.bind(this);
		initView();
		setAdapter();
	}

	/**
	 * 在setContentView之前，设置的参数
	 */
	public void setParams(){};


	/**
	 * 设置适配器
	 */
	protected void setAdapter() {

	}

	/**
	 * 添加布局ID,初始化布局
	 *
	 * @return
	 */
	protected abstract int getLayoutId();

	/**
	 * 执行查找控件等基本操作
	 */
	protected abstract void initView();


	@Override
	protected void onDestroy() {
		super.onDestroy();
		releaseResource();
		ButterKnife.unbind(this);
	}

	protected void isLand(){
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
	}


	/**
	 * 结束应用的时候释放资源
	 */
	protected abstract void releaseResource();


	//沉浸式状态栏
	/*@Override
	public void onWindowFocusChanged(boolean hasFocus){
		super.onWindowFocusChanged(hasFocus);
		if (hasFocus && Build.VERSION.SDK_INT >= 19) {
			View decorView = getWindow().getDecorView();
			decorView.setSystemUiVisibility(
					View.SYSTEM_UI_FLAG_LAYOUT_STABLE
							| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
							| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
							| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
							| View.SYSTEM_UI_FLAG_FULLSCREEN
							| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
		}
	}*/

}

